| Conditions | 1 |
| Paths | 3 |
| Total Lines | 95 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /** |
||
| 123 | init: function() { |
||
| 124 | var |
||
| 125 | page, hostname, |
||
| 126 | headers = {}, |
||
| 127 | a = document.createElement('a'), |
||
| 128 | json = JSON.parse(require('fs').read('apps.json')); |
||
| 129 | |||
| 130 | wappalyzer.log('driver.init'); |
||
| 131 | |||
| 132 | a.href = url.replace(/#.*$/, ''); |
||
| 133 | |||
| 134 | hostname = a.hostname; |
||
| 135 | |||
| 136 | wappalyzer.apps = json.apps; |
||
| 137 | wappalyzer.categories = json.categories; |
||
| 138 | |||
| 139 | page = require('webpage').create(); |
||
| 140 | |||
| 141 | page.settings.loadImages = false; |
||
| 142 | page.settings.userAgent = 'Mozilla/5.0 (compatible; Wappalyzer; +https://github.com/AliasIO/Wappalyzer)'; |
||
| 143 | page.settings.resourceTimeout = resourceTimeout; |
||
| 144 | |||
| 145 | page.onError = function(message) { |
||
| 146 | wappalyzer.log(message, 'error'); |
||
| 147 | }; |
||
| 148 | |||
| 149 | page.onResourceTimeout = function() { |
||
| 150 | wappalyzer.log('Resource timeout', 'error'); |
||
| 151 | |||
| 152 | wappalyzer.driver.sendResponse(); |
||
| 153 | |||
| 154 | phantom.exit(1); |
||
| 155 | }; |
||
| 156 | |||
| 157 | page.onResourceReceived = function(response) { |
||
| 158 | if ( response.url.replace(/\/$/, '') === url.replace(/\/$/, '') ) { |
||
| 159 | if ( response.redirectURL ) { |
||
| 160 | url = response.redirectURL; |
||
| 161 | |||
| 162 | return; |
||
| 163 | } |
||
| 164 | |||
| 165 | if ( response.stage === 'end' && response.status === 200 && response.contentType.indexOf('text/html') !== -1 ) { |
||
| 166 | response.headers.forEach(function(header) { |
||
| 167 | headers[header.name.toLowerCase()] = header.value; |
||
| 168 | }); |
||
| 169 | } |
||
| 170 | } |
||
| 171 | }; |
||
| 172 | |||
| 173 | page.onResourceError = function(resourceError) { |
||
| 174 | wappalyzer.log(resourceError.errorString, 'error'); |
||
| 175 | }; |
||
| 176 | |||
| 177 | page.open(url, function(status) { |
||
| 178 | var html, environmentVars = ''; |
||
| 179 | |||
| 180 | if ( status === 'success' ) { |
||
| 181 | html = page.content; |
||
| 182 | |||
| 183 | if ( html.length > 50000 ) { |
||
| 184 | html = html.substring(0, 25000) + html.substring(html.length - 25000, html.length); |
||
| 185 | } |
||
| 186 | |||
| 187 | // Collect environment variables |
||
| 188 | environmentVars = page.evaluate(function() { |
||
| 189 | var i, environmentVars = ''; |
||
| 190 | |||
| 191 | for ( i in window ) { |
||
| 192 | environmentVars += i + ' '; |
||
| 193 | } |
||
| 194 | |||
| 195 | return environmentVars; |
||
| 196 | }); |
||
| 197 | |||
| 198 | wappalyzer.log({ message: 'environmentVars: ' + environmentVars }); |
||
| 199 | |||
| 200 | environmentVars = environmentVars.split(' ').slice(0, 500); |
||
| 201 | |||
| 202 | wappalyzer.analyze(hostname, url, { |
||
| 203 | html: html, |
||
| 204 | headers: headers, |
||
| 205 | env: environmentVars |
||
| 206 | }); |
||
| 207 | |||
| 208 | phantom.exit(0); |
||
| 209 | } else { |
||
| 210 | wappalyzer.log('Failed to fetch page', 'error'); |
||
| 211 | |||
| 212 | wappalyzer.driver.sendResponse(); |
||
| 213 | |||
| 214 | phantom.exit(1); |
||
| 215 | } |
||
| 216 | }); |
||
| 217 | } |
||
| 218 | }; |
||
| 229 |